package com.wenwei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.wenwei.bean.MessageListBean;
import com.wenwei.parking.R;
import com.wenwei.utils.RogerDateUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/31.
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MyViewHolder>{

    public interface CallBack{
        void onItemClick(MessageListBean.DataBean bean);
    }

    private CallBack mCallBack;


    public void setmCallBack(CallBack callBack){
        this.mCallBack = callBack;
    }

    private List<MessageListBean.DataBean> mList;
    public void setDataList(List<MessageListBean.DataBean> list){
        this.mList = list;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message,null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onItemClick(mList.get(position));
            }
        });
        holder.messageName.setText(mList.get(position).getTitle());
        holder.messageContent.setText(mList.get(position).getContent());
        holder.messageTime.setText(RogerDateUtils.getDateToString(mList.get(position).getTimes()));
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.message_name)
        TextView messageName;
        @Bind(R.id.message_time)
        TextView messageTime;
        @Bind(R.id.message_content)
        TextView messageContent;
        public MyViewHolder(View view){
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
